package com.hh.ListNodeQuestions;

/**
 * @Author hanghao
 * @Date 2023/6/28 14:50
 * @Version 1.0
 * middle
 * 奇偶链表    (递归函数系列 + 双指针)    注：这题是我第一次做的
 */

public class No328 {
    public ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode oddNode = head;        //奇数
        ListNode evenNode = head.next;  //偶数
        ListNode evenHead = evenNode;
        while (evenNode != null && evenNode.next != null) {
            oddNode.next = evenNode.next;
            oddNode = oddNode.next;
            evenNode.next = oddNode.next;
            evenNode = evenNode.next;
        }
        oddNode.next = evenHead;
        return head;
    }
}
